package io.renren.modules.job.task;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.ouganyun.iot.protocol.JsonUtil;
import com.ouganyun.iot.protocol.shuiBiao.NBDianBiaoLiProtocol;
import com.ruoyi.tcpServer.shuiDianApi.model.CommandModel;
import com.ruoyi.tcpServer.shuiDianApi.service.RemoteShuiDianService;
import io.renren.modules.delay.DelayQueueManager;
import io.renren.modules.delay.DelayTask;
import io.renren.modules.delay.ReportTaskBase;
import io.renren.modules.equipment.EquipmentEntity;
import io.renren.modules.equipment.EquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class MeterTask implements ITask{
  @Autowired
  private EquipmentService equipmentService;
  @Autowired
  private DelayQueueManager delayQueueManager;
  @Autowired
  private RemoteShuiDianService remoteShuiDianService;
  @Override
  public void run(String buildingId) {
    List<EquipmentEntity> equipments = equipmentService.listByBuildingId(buildingId);
    for (EquipmentEntity equipment : equipments) {
      CommandModel commandModel = new CommandModel();
      commandModel.setDeviceId(equipment.getId());
//      ObjectNode json = JsonUtil.createJson();
//      json.put("sn", equipment.getSn());
//      String remoteCallCommand = NBDianBiaoLiProtocol.remoteControlRequest("remoteCall", json);
      commandModel.setCommand("remoteCall");
      remoteShuiDianService.sendCommand(commandModel);
    }
//    delayQueueManager.put(new DelayTask(new ReportTaskBase(buildingId, buildingId), 60 * 1000));
  }
}
